package com.atguigu.srb.core.controller.admin;

import com.atguigu.common.result.R;
import com.atguigu.srb.core.pojo.entity.Borrower;
import com.atguigu.srb.core.pojo.vo.BorrowerApprovalVO;
import com.atguigu.srb.core.pojo.vo.BorrowerDetailVO;
import com.atguigu.srb.core.service.BorrowerService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "借款人管理")
@Slf4j
@RestController
@RequestMapping("/admin/core/borrower")
public class AdminBorrowerController {
    @Resource
    private BorrowerService borrowerService;

    @GetMapping("/list/{page}/{limit}")
    public R getListPage(@ApiParam(value = "页数", required = false) @PathVariable Integer page,
                         @ApiParam(value = "条数", required = false) @PathVariable Integer limit,
                         @ApiParam(value = "查询关键字", required = false) @RequestParam String keyword){
        Page<Borrower> pageParam=new Page<>(page,limit);
        IPage<Borrower> pageModel=borrowerService.getListPage(pageParam,keyword);
        return R.ok().data("pageModel",pageModel);
    }
    @ApiOperation("展示借款人信息")
    @GetMapping("/show/{id}")
    public R showBorrower(@PathVariable Long id){
        BorrowerDetailVO borrowerDetailVO=borrowerService.getBorrowerDetailVOById(id);
        return R.ok().data("borrowerDetailVO",borrowerDetailVO);
    }
    @ApiOperation("借款额度审批")
    @PostMapping("/approval")
    public R approval(@RequestBody BorrowerApprovalVO borrowerApprovalVO){
        borrowerService.approvalBorrower(borrowerApprovalVO);
        return R.ok().message("审批完成");
    }
}
